package com.woniuxy03;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-06-04 16:31
 */
public class Test02 {
    public static void main(String[] args) {
        String str="abcdef";
        System.out.println(reverse(str));
        System.out.println(reverse02(str));
        System.out.println(reverse03(str));
        System.out.println(reverse04(str));
    }

    public static String reverse04(String str) {
        return new StringBuilder(str).reverse().toString();
    }

    public static String reverse03(String str) {
        char[] oldArray = str.toCharArray();
        for (int i = 0,j=oldArray.length - i - 1; i < j; i++,j--) {
            char temp = oldArray[i];
            oldArray[i] = oldArray[j];
            oldArray[j] = temp;
        }
       return new String(oldArray);
    }
    public static String reverse02(String str) {
        char[] oldArray = str.toCharArray();
        for (int i = 0; i < oldArray.length/2; i++) {
            char temp = oldArray[i];
            oldArray[i] = oldArray[oldArray.length - i - 1];
            oldArray[oldArray.length - i - 1] = temp;
        }
       return new String(oldArray);
    }



    public static String reverse(String str) {
        char[] oldArray = str.toCharArray();
        char[] newArray = new char[oldArray.length];
        for (int i = 0; i < oldArray.length; i++) {
            newArray[oldArray.length-i-1] = oldArray[i];
        }
        return new String(newArray);
    }
}
